package com.terana.lbs.marketing.web.consumer;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.pojo.marketing.param.UserCouponsParam;
import com.terana.lbs.marketing.web.event.input.CouponInput;
import com.terana.lbs.marketing.web.service.CouponService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class UserGetCouponConsumer {
    @Autowired
    private CouponService couponService;

    @StreamListener("user-get-coupon-input")
    public void handleUserGetCoupon(UserCouponsParam param){
        log.info("消费消息:"+param);
        try {
            couponService.saveUserReceiveCoupon(param);
        }catch (BusinessException e){
            log.error("领取优惠券 失败 业务异常",e);
        }catch (Throwable e){
            log.error("领取优惠券 失败 系统异常",e);
            throw e;
        }



    }
}
